package com.yike.user.controller;

import com.yike.user.entity.PlatformRoleMenu;
import com.yike.user.param.PlatformRoleMenuParam;
import com.yike.user.service.PlatformRoleMenuService;
import com.yike.user.vo.PlatformMenuTreeVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.PlatformRoleMenuPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 平台角色菜单 控制器
 *
 * @author Sakura
 * @since 2024-10-29
 */
@Slf4j
@RestController
@RequestMapping("/platform/roleMenu")
@Module("user")
@Api(value = "平台角色菜单API", tags = {"平台角色菜单"})
public class PlatformRoleMenuController extends BaseController {

    @Autowired
    private PlatformRoleMenuService platformRoleMenuService;

    /**
     * 保存平台角色菜单
     */
    @PostMapping("/save")
    @OperationLog(name = "保存角色菜单", type = OperationLogType.ADD)
    @ApiOperation(value = "保存角色菜单", response = ApiResult.class)
    public ApiResult<Boolean> save(@Validated(Add.class) @RequestBody PlatformRoleMenuParam platformRoleMenuParam) throws Exception {
        boolean flag = platformRoleMenuService.save(platformRoleMenuParam);
        return ApiResult.result(flag);
    }


    /**
     * 平台角色菜单
     */
    @GetMapping("/getMenus/{roleId}")
    //@OperationLog(name = "获取角色菜单信息", type = OperationLogType.PAGE)
    @ApiOperation(value = "获取角色菜单信息", response = PlatformRoleMenu.class)
    public ApiResult<List<PlatformMenuTreeVo>> getMenus(@PathVariable("roleId") Long roleId) throws Exception {
        List<PlatformMenuTreeVo> platformMenuTreeVos = platformRoleMenuService.getMenus(roleId);
        return ApiResult.ok(platformMenuTreeVos);
    }

    /**
     * 平台角色菜单
     */
    @GetMapping("/getMenuIds/{roleId}")
    //@OperationLog(name = ""获取角色菜单id"", type = OperationLogType.PAGE)
    @ApiOperation(value = "获取角色菜单id", response = ApiResult.class)
    public ApiResult<List<Long>> getMenuIds(@PathVariable("roleId") Long roleId) throws Exception {
        List<Long> menuIds = platformRoleMenuService.getMenuIds(roleId);
        return ApiResult.ok(menuIds);
    }


}

